//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Diagnostics.Contracts;
using OpenLS.Core.Serialization;

namespace OpenLS.Spreadsheet.Internals
{
    class CommentInternal : IOfficeXmlSerializable
    {

         private string _ref;

        public string Ref
        {
            get { return _ref; }
            set { _ref = value; }
        }
        private int _authorId;

        public int AuthorId
        {
            get { return _authorId; }
            set { _authorId = value; }
        }
        private string _guid;

        public string Guid
        {
            get { return _guid; }
            set { _guid = value; }
        }

        private RichTextParagraph _text = new RichTextParagraph();

        public RichTextParagraph Text
        {
            get { return _text; }
            set
            {
                Contract.Requires(value != null);
                _text = value;
            }
        }



        #region IOfficeXmlSerializable Members
        void IOfficeXmlSerializable.ReadXml(ReadContext context)
        {
            using (ReadContext c = context.Read("comment"))
            {
                Ref = c.GetString("ref");
                AuthorId = c.GetInteger("authorId");
                Guid = c.GetOptionalString("guid");
                Text = c.ReadElementAs<RichTextParagraph>("text");
            }
        }

        void IOfficeXmlSerializable.WriteXml(WriteContext context)
        {
            using (WriteContext c = context.Write("comment"))
            {
                c.SetString("ref", Ref);
                c.SetInteger("authorId", AuthorId);
                c.SetOptionalString("guid", Guid);
                c.WriteElementAs(Text, "text");
            }
        }

        #endregion
    }
}
